package com.example.teaching_server.entity;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.*;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import java.time.LocalDateTime;

/**
 * 教学资源类型实体类
 *
 * @author Teaching Server
 * @since 1.0.0
 */
@Getter
@Setter
@ToString
@EqualsAndHashCode(of = "id")
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "teaching_resource_types", indexes = {
        @Index(name = "idx_type_code", columnList = "code"),
        @Index(name = "idx_type_sort", columnList = "sort_order")
})
public class TeachingResourceType {

    /**
     * 类型ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    /**
     * 类型名称
     */
    @NotBlank(message = "类型名称不能为空")
    @Size(max = 50, message = "类型名称长度不能超过50个字符")
    @Column(nullable = false, unique = true, length = 50)
    private String name;

    /**
     * 类型代码
     */
    @NotBlank(message = "类型代码不能为空")
    @Size(max = 20, message = "类型代码长度不能超过20个字符")
    @Column(nullable = false, unique = true, length = 20)
    private String code;

    /**
     * 类型图标
     */
    @Size(max = 100, message = "类型图标长度不能超过100个字符")
    @Column(length = 100)
    private String icon;

    /**
     * 排序顺序
     */
    @Builder.Default
    @Column(name = "sort_order")
    private Integer sortOrder = 0;

    /**
     * 验证类型是否有效
     */
    public boolean isValid() {
        return name != null && !name.trim().isEmpty() &&
                code != null && !code.trim().isEmpty();
    }

    /**
     * 获取显示名称
     */
    public String getDisplayName() {
        return name + " (" + code + ")";
    }
}
